Skip to main content

Prerequisites

GDAL Scripts requires Python 3.x and the GDAL library with Python bindings. The recommended approach is to use Anaconda, which simplifies GDAL installation and dependency management.
Python 2 versions of some scripts exist in the repository for legacy support, but Python 3 is strongly recommended for all new installations.

Installation Steps

1

Install Anaconda (Recommended)

If you don’t already have Anaconda installed, download it from anaconda.com.Anaconda provides the easiest path to getting GDAL installed with all necessary dependencies.
2

Install GDAL

GDAL is the core dependency for all scripts in this collection. Install it using conda:
conda install gdal
This command installs GDAL along with the Python bindings automatically.
If you prefer not to use Anaconda, you can install GDAL via other methods:On Ubuntu/Debian:
sudo apt-get update
sudo apt-get install gdal-bin python3-gdal
On macOS with Homebrew:
brew install gdal
pip install gdal==$(gdal-config --version)
On Windows: Download OSGeo4W installer from osgeo.org and select GDAL during installation.
3

Install Additional Python Dependencies

Several scripts require NumPy and SciPy for numerical operations:
conda install numpy scipy
Or using pip:
pip install numpy scipy
Not all scripts require these dependencies. Check individual script README files for specific requirements.
4

Clone the Repository

Clone the GDAL Scripts repository from GitHub:
git clone https://github.com/thareUSGS/GDAL_scripts.git
cd GDAL_scripts
The scripts are ready to use immediately - no build or install step is required.
5

Test Your Installation

Verify that GDAL is correctly installed by checking the version:
gdalinfo --version
Test the Python bindings:
python -c "from osgeo import gdal; print(gdal.__version__)"
Both commands should return version information without errors.

Verifying Individual Scripts

Most scripts provide usage information when run without arguments:
python gdal2Coordinates/pixel2longlat.py
Each should display usage instructions, confirming the script is ready to use.

Common Issues and Troubleshooting

This error indicates GDAL Python bindings are not installed or not in your Python path.Solution:
  • If using Anaconda: conda install gdal
  • If using pip: pip install gdal
  • Ensure you’re using the same Python environment where GDAL was installed
Check your Python environment:
which python
conda env list  # if using Anaconda
Some scripts require NumPy and SciPy for array operations and filtering.Solution:
conda install numpy scipy
or
pip install numpy scipy
Scripts requiring these dependencies include:
  • gdal_baseline_slope.py (requires both)
  • Various terrain analysis tools
If you see errors about GDAL version mismatches between the library and Python bindings:Solution with Anaconda (recommended):
conda update gdal
Solution with pip:
pip install gdal==$(gdal-config --version)
This ensures the Python bindings match your GDAL library version.
Solution: Make scripts executable:
chmod +x gdal2Coordinates/pixel2longlat.py
./gdal2Coordinates/pixel2longlat.py
Or always run with Python explicitly:
python gdal2Coordinates/pixel2longlat.py
Some scripts, particularly gdal_baseline_slope.py, load entire images into memory.Solutions:
  • Work with smaller regions of interest
  • Use 8-bit output (-ot Byte flag) instead of 32-bit when possible
  • Increase available system memory
  • Process images in tiles for very large datasets
From the gdal_baseline_slope.py README:
“Current implementation loads full image into memory and is fairly slow.”

Environment Setup Tips

Creating a Dedicated Conda Environment

For cleaner dependency management, create a dedicated environment:
conda create -n planetary-tools python=3.9 gdal numpy scipy
conda activate planetary-tools
Activate this environment whenever working with GDAL Scripts:
conda activate planetary-tools

Adding Scripts to Your PATH

To run scripts from anywhere without specifying full paths:
export PATH="$PATH:/path/to/GDAL_scripts"
Add this line to your ~/.bashrc or ~/.zshrc to make it permanent.

System Requirements

Minimum Requirements

  • Python 3.6+
  • GDAL 2.0+
  • 4GB RAM (for small images)
  • Any major OS (Linux, macOS, Windows)

Recommended

  • Python 3.9+
  • GDAL 3.0+
  • 16GB+ RAM (for large planetary datasets)
  • SSD storage for faster I/O

Next Steps

Quick Start Guide

Now that you have GDAL Scripts installed, try out some practical examples